# 切换到项目根目录
Set-Location (Join-Path $PSScriptRoot "..")

# 旧文件清理
if (Test-Path ".\stress_tester") {
    Remove-Item ".\stress_tester" -Force
    Write-Host "remove old stress_tester"
}
if (Test-Path ".\stress_tester.zip") {
    Remove-Item ".\stress_tester.zip" -Force
    Write-Host "remove old stress_tester.zip"
}

# 设置交叉编译环境变量
$env:GOOS = "linux"
$env:GOARCH = "amd64"
$env:CGO_ENABLED = "0"

# 编译主程序
go build -o stress_tester

# 打包为 zip 文件
Compress-Archive -Path "stress_tester", "conf", ".\script\start.sh" -DestinationPath "stress_tester.zip"

Write-Host "build success: stress_tester.zip"
